import { IEmployeeCreateInfo } from "@src/interface";
import {DatabaseService} from '@src/db';
import { v4 as uuidv4 } from 'uuid';

export namespace EmployeeService{
    export async function add(info:IEmployeeCreateInfo){
        const query = `SELECT * FROM employee WHERE username = '${info.username}'`;
        console.log(query)
        let rows = await DatabaseService.query(query);
        if(rows.length > 0){
            throw new Error("username exists");
        }
        let collection = await DatabaseService.getCollection("employee");
        let id = uuidv4();
        let rst = await collection.insert(id,info);
        return {
            id:id,
            username:info.username
        }
    }
}